package com.dsteiner.xelavos.client;


import com.dsteiner.widgets.client.PopupOverlayWidget;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.HorizontalPanelExt;
import com.dsteiner.widgets.client.Widgets.ImageExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PopupOverlayModel;
import com.dsteiner.xelavos.client.controller.UserStatsController;
import com.dsteiner.xelavos.client.model.AuthenticationModel;
import com.dsteiner.xelavos.client.model.DisplayModel;
import com.dsteiner.xelavos.client.model.UserStatsModel;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class UserStatsWidget extends LazyWidget {

	private UserStatsController userStatsController = new UserStatsController();
	private final UserStatsModel userStatsModel;
	private final AuthenticationModel authenticationModel;

	public UserStatsWidget(UserStatsModel userStatsModel, AuthenticationModel authenticationModel) {
		this.userStatsModel = userStatsModel;
		this.authenticationModel = authenticationModel;
		setStyleName(XelavosResources.INSTANCE.css().userStatsWidget());
	}

	@Override
	public Widget createContentWidget() {
		HorizontalPanel mainPanel = new HorizontalPanel();
		HTMLExt infoHtml = new HTMLExt();
		HTMLExt lastLoggedInUserHtml = new HTMLExt();
		ImageExt lastLoggedInUserImage = new ImageExt();
		DisplayModel userDisplayModel = new DisplayModel();
		DisplayWidget userDisplayWidget = new DisplayWidget(userDisplayModel, authenticationModel);
		PopupOverlayModel userPopupOverlayModel = new PopupOverlayModel();
		userPopupOverlayModel.setContentWidget(userDisplayWidget);
		PopupOverlayWidget userPopupOverlayWidget = new PopupOverlayWidget(userPopupOverlayModel);
		HorizontalPanelExt userPanel = new HorizontalPanelExt();
//		RoundBorderCssResource css = RoundBorderResources.Util.INSTANCE.css();
//		RoundBorderModel roundBorderModel = new RoundBorderModel();
//		roundBorderModel.setContentWidget(mainPanel);
//		roundBorderModel.setCssResource(css);
//		RoundBorder decoratorPanel = new RoundBorder(roundBorderModel);
		userPanel.add((Widget)new HTML("ultimo login de "));
		userPanel.add((Widget)lastLoggedInUserImage);
		userPanel.add((Widget)lastLoggedInUserHtml);
		
		mainPanel.add((Widget)infoHtml);
		mainPanel.add((Widget)userPanel);
		
		lastLoggedInUserImage.addStyleName(XelavosResources.INSTANCE.css().mainImg());
		lastLoggedInUserHtml.addStyleName(XelavosResources.INSTANCE.css().userHtml());
		
		userStatsController.registerUserStatsWidget(this);
		userStatsController.registerUserStatsModel(userStatsModel);
		userStatsController.registerInfoHtml(infoHtml);
		userStatsController.registerLastLoggedInUserImage(lastLoggedInUserImage);
		userStatsController.registerLastLoggedInUserHtml(lastLoggedInUserHtml);
		userStatsController.registerUserPanel(userPanel);
		userStatsController.registerUserDisplayModel(userDisplayModel);
		userStatsController.registerUserPopupOverlayModel(userPopupOverlayModel);
		return mainPanel;
	}

}